
public class db_lock {
	public int iReaders;
	public int iWriters;
	public void getWriteLock () throws Exception{
		synchronized(this) {
			while (iReaders > 0 || iWriters > 0)
				this.wait();
			iWriters++;
		}
	}
	public void getReadLock() throws Exception{
		synchronized(this) {
			while (iWriters > 0) 
				this.wait();
			iReaders++;
		}
	}
	public void releaseReadLock() {
		synchronized(this) {
			iReaders--;
			this.notifyAll();
		}
	}
	public void releaseWriteLock() {
		synchronized(this) {
			iWriters--;
			this.notifyAll();
		}
	}
}
